<?php
/**
 +------------------------------------------------------------------------------
 * @author   heihei2202 <admin@sameus.com>
 * @version    2012-05-15 04:59:14Z heihei2202 $
 +------------------------------------------------------------------------------
 */
// 本类由系统自动生成，仅供测试用途
class LoginAction extends HomeAction {
  protected function subpsd($data){
      //处理特殊密码
      $data=md5($data);
      return $dd=substr($data,0,2).$data;
  }
   public function index(){
//       $dd=md5('as139579');
//       
//       $dd=substr($dd,0,2).$dd;
    //  dump($dd);
      $this->display('login');
  }  
  public function  CheckLogin(){
     
      $user=M('User');
      $data['user_email']=$_POST['user_email'];
      $psd=$this->subpsd($_POST['password']);//特殊处理后的密码保存
      $data['user_psd']=$psd; 
      if($authInfo=$user->where($data)->field('id,user_name,user_email')->find()){
        $_SESSION[C('USER_AUTH_KEY')] =$authInfo['id'];
        $_SESSION['uid'] =$authInfo['id'];
        $_SESSION['uname'] =$authInfo['user_name'];
        $_SESSION['uemail'] =$authInfo['user_email'];
        $this->assign("jumpUrl",__APP__.'/Center?uid='.$_SESSION['uid']);
        $this->success('登录成功！');
        
      }else{
          $this->error('登录失败,请检查用户名或者密码');
      }
  }
  public function regist(){
         
      $this->display('regist');
  }  
   public function  CheckRegist(){
       $use=D('User');
       if($udata=$use->create()){
           //特殊处理后的密码保存
           $udata['user_psd']=$this->subpsd($udata['user_psd']);
           $udata['create_time']=date('Y-m-d H:i:m',time());
           if($uid=$use->add($udata)){
                $_SESSION[C('USER_AUTH_KEY')] =$uid;
                $_SESSION['uid'] =$uid;
                $_SESSION['uname'] =$udata['user_name'];
                $_SESSION['uemail'] =$udata['user_email'];
                 $this->assign("jumpUrl",__APP__.'/Center?uid='.$_SESSION['uid']);
                 $this->success('注册成功');
           }else{
                $this->error($use->getError());
           }
           
       }else{
           $this->error($use->getError());
       }
   }	
   //新用户通过加入群组验证,如果已存在密码,则直接调取登陆框,否则显示从新设置密码框页面
   public function Rvalidate(){
       
   }


   // 用户登出
    public function logout() {
        if(isset($_SESSION[C('USER_AUTH_KEY')])) {
			unset($_SESSION[C('USER_AUTH_KEY')]);
			unset($_SESSION);
			session_destroy();
            $this->assign("jumpUrl",__URL__);
            $this->success('登出成功！');
        }else {
            $this->error('已经登出！');
        }
    }
}